package controllers

import (
	"encoding/json"
	"wego/models"
)

type MenuController struct {
	BaseController
}

func (this *MenuController) MenuList() {
	list, count := models.MenuList()
	result := models.ResultList{
		List:  list,
		Count: count,
	}
	this.JsonResult(1, "操作成功", &result)
}

func (this *MenuController) MenuSave() {
	params := models.Menu{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	id, err := models.MenuSave(&params)
	if err != nil {
		this.JsonResult(0, "操作失败", "")
	} else {
		this.JsonResult(1, "操作成功", id)
	}
}

func (this *MenuController) MenuStatus() {
	params := models.Menu{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	id, err := models.MenuStatus(&params)
	if err != nil {
		this.JsonResult(0, "操作失败", "")
	} else {
		this.JsonResult(1, "操作成功", id)
	}
}

func (this *MenuController) MenuDel() {
	params := models.Menu{}
	_ = json.Unmarshal(this.Ctx.Input.RequestBody, &params)
	err := models.MenuDel(&params)
	if err != nil {
		this.JsonResult(0, "操作失败", "")
	} else {
		this.JsonResult(1, "操作成功", "")
	}
}
